package com.yan.crowd.controller;

import com.yan.crowd.entity.vo.DetailProjectVO;
import com.yan.crowd.entity.vo.PortalTypeVO;
import com.yan.crowd.entity.vo.ProjectVo;
import com.yan.crowd.service.ProjectService;
import com.yan.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProjectProviderController {

    @Autowired
    private ProjectService projectService;

    @RequestMapping("/save/project/vo/remote")
    public ResultEntity<String> saveProjectVORemote(@RequestBody ProjectVo projectVo, @RequestParam("memberId") Integer memberId) {

        try {
            projectService.saveProjectVORemote(projectVo, memberId);
            return ResultEntity.successWithoutData();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/get/portal/type/project/data/remote")
    public ResultEntity<List<PortalTypeVO>> getPortalTypeVO(){

        try{
            List<PortalTypeVO> portalTypeVO = projectService.getPortalTypeVO();
            return ResultEntity.successWithData(portalTypeVO);
        } catch (Exception e){
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }

    }

    @RequestMapping("/get/project/detail/remote/{id}")
    public ResultEntity<DetailProjectVO> getDetailProjectVORemote(@PathVariable("id")Integer id){
        try{
            DetailProjectVO detailProjectVo = projectService.getDetailProjectVo(id);
            return ResultEntity.successWithData(detailProjectVo);
        } catch (Exception e){
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }
}
